package com.aiju.cash.ui.member;

import android.content.Intent;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.aiju.base.activity.BaseTitleActivity;
import com.aiju.cash.R;
import com.aiju.utils.EmojiFilter;

/**
 * @author: 佐为
 * @date: 2017-02-20 15:59
 * @version: V1.0
 * @Description: 详细地址，备注
 */
public class MemberRemarkActivity extends BaseTitleActivity {

    public static final int RESULT_MORE_CODE = 100;
    public static final int RESULT_REMARK_CODE = 101;

    private int type;
    private EditText remarkEditText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_member_remark);
        type = getIntent().getIntExtra("type", 0);
        String data = getIntent().getStringExtra("data");

        setRightTitle("保存");
        remarkEditText = (EditText) findViewById(R.id.ev_member_remark);
        remarkEditText.setFilters(new InputFilter[]{new EmojiFilter()});
        if (type == 0) {
            setCenterTitle("编辑详细地址");
            remarkEditText.setHint("请输入详细的地址，支持汉字、数字、英文,限50字");
        } else {
            setCenterTitle("编辑会员备注");
            remarkEditText.setHint("请输入详细的备注，支持汉字、数字、英文,限50字");
        }
        if (!TextUtils.isEmpty(data)) {
            remarkEditText.setText(data);
            remarkEditText.setSelection(data.length());
        }
        mAiJuTitleBarView.setRightOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goBackForResult();
            }
        });
    }

    @Override
    public void onBackPressed() {
        goBackForResult();
    }

    /**
     * 带返回值的后退
     */
    private void goBackForResult() {
        Intent intent = new Intent();
        intent.putExtra("second", remarkEditText.getText().toString());
        if (type == RESULT_MORE_CODE) {
            setResult(RESULT_MORE_CODE, intent);
        } else {
            setResult(RESULT_REMARK_CODE, intent);
        }
        finish();
    }
}
